﻿using Hidistro.Entities.Commodities;
using Hidistro.SaleSystem.Catalog;
using Hidistro.UI.Common.Controls;
using System;
using System.Data;
using System.Data.OleDb;
using System.Web.UI.WebControls;

namespace Hidistro.UI.SaleSystem.Tags
{
    public class wnxd_Article : AscxTemplatedWebControl
    {
        protected override void AttachChildControls()
        {
            int categoryId;
            if (int.TryParse(this.Page.Request.QueryString["CategoryId"], out categoryId))
            {
                this.FindControl("box").Visible = true;
                CategoryInfo category = CategoryBrowser.GetCategory(categoryId);
                if (category != null && category.ParentCategoryId != 0)
                {
                    string ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + this.MapPathSecure("~/qingqu/data/#6Fy1Do.mdb") + ";";
                    using (OleDbConnection cnn = new OleDbConnection(ConnectionString))
                    {
                        string sql = string.Format("select top {0} t1.title,t1.id,t2.catedir from sd_content as t1 left join sd_category as t2 on t1.classid = t2.cateid where t2.catename = '{1}' order by lastupdate desc", 8, category.Name);
                        OleDbCommand cmd = new OleDbCommand(sql, cnn);
                        OleDbDataAdapter da = new OleDbDataAdapter();
                        da.SelectCommand = cmd;
                        DataSet ds = new DataSet();
                        da.Fill(ds);
                        Repeater list = (Repeater)this.FindControl("list");
                        list.DataSource = ds.Tables[0];
                        list.DataBind();
                    }

                }
            }
        }
        protected override void OnInit(EventArgs e)
        {
            if (this.SkinName == null)
            {
                this.SkinName = "/ascx/tags/Common_GoodsList/wnxd_Article.ascx";
            }
            base.OnInit(e);
        }
    }
}